#include "main.h"
#include "gui.h"

extern linpvr_t linpvr;

/*********************************************************************
   Splash Window
**********************************************************************/

/*********************************************************************
   Devices Window
**********************************************************************/

void on_choose_device_clicked(GtkButton *button, gpointer user_data) {
  
}

void on_show_capabilities_clicked(GtkButton *button, gpointer user_data)
{
  GtkWindow *devices = GTK_WINDOW(glade_xml_get_widget(linpvr.glade,"devices"));
  GtkTreeView *tree = GTK_TREE_VIEW(glade_xml_get_widget(linpvr.glade,"devices_list"));
  GtkTreeSelection *selection = gtk_tree_view_get_selection(tree);
  GtkTreeModel *model = gtk_tree_view_get_model(tree) ;
  GtkTreeIter iter;
  gchar *path;
  videodev_t video;

  if (gtk_tree_selection_get_selected(selection, &model, &iter)) {

    gtk_tree_model_get(model, &iter, 1, &path, -1);

    if (videodev_open(&video, path) < 0) {
      show_error_report(linpvr.glade, "Can't get details of this device");
      return;
    }    

    show_videodev_info(linpvr.glade, devices, &video);
    videodev_close(&video);
    g_free(path);
  }
}

void on_cancel_devices_clicked(GtkButton *button, gpointer user_data)
{
  gtk_widget_hide(glade_xml_get_widget(linpvr.glade,"devices"));
}

void on_choose_dev_activate(GtkMenuItem *menuitem, gpointer user_data)
{
  GtkWindow *mainwin = GTK_WINDOW(glade_xml_get_widget(linpvr.glade,"mainwin"));
  show_devices_list(linpvr.glade, mainwin);
}

/***********************************************************************
   Main Window
***********************************************************************/

void on_record_clicked(GtkButton *button, gpointer user_data) {
  linpvr_switch_mode(&linpvr, MODE_RECORD);
}

void on_stop_clicked(GtkButton *button, gpointer user_data) {
  linpvr_switch_mode(&linpvr, MODE_TV);
}

void on_eksport_activate(GtkMenuItem *menuitem, gpointer user_data) {
}


void on_capabilities_activate(GtkMenuItem *menuitem, gpointer user_data)
{
  GtkWindow *mainwin = GTK_WINDOW(glade_xml_get_widget(linpvr.glade,"mainwin"));
  show_videodev_info(linpvr.glade, mainwin, &linpvr.video);
}

void on_about_activate(GtkMenuItem *menuitem, gpointer user_data)
{
  GtkWidget *splash = glade_xml_get_widget(linpvr.glade, "splash");
  gtk_widget_show(splash);
}

void on_exit_activate(GtkMenuItem *menuitem, gpointer user_data)
{
  linpvr_main_quit();
}

gboolean mainwin_delete (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
  linpvr_main_quit();
  return TRUE;
}

/***********************************************************************
   Capabilities Window
***********************************************************************/

void on_capabilities_close_clicked(GtkButton *button, gpointer user_data)
{
  gtk_widget_hide(glade_xml_get_widget(linpvr.glade,"capabilities"));
}
